﻿using MediatR;
using S.Services.SheepMale.Api.Application.Command.SheepMaleCommand;
using S.Services.SheepMale.Domain.PurchaseSales;
using S.Services.SheepMale.Infrastructure;

namespace S.Services.SheepMale.Api.Application.CommandHandler.SheepMaleCommandHandler
{
    public class SheepFatherAllDelCommandHandler : IRequestHandler<SheepFatherAllDelCommand, int>
    {
        private readonly IRepository<SheepMaleInfo> repository;

        public SheepFatherAllDelCommandHandler(IRepository<SheepMaleInfo> repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(SheepFatherAllDelCommand request, CancellationToken cancellationToken)
        {
            string[] ids = request.maleId.ToString().Split(',');
            foreach (var item in ids)
            {
                await repository.DeleteAsync(int.Parse(item));
            }
            return 1;
        }
    }
}
